package com.rogue.employee.controller;

import com.github.pagehelper.PageInfo;
import com.rogue.common.core.utils.ResultDTO;
import com.rogue.employee.domain.HsEmployee;
import com.rogue.employee.domain.dto.DeptDTO;
import com.rogue.employee.domain.dto.ExamineDTO;
import com.rogue.employee.domain.dto.HsEmployeeDTO;
import com.rogue.employee.domain.vo.EmployeeVo;
import com.rogue.employee.service.HsEmployeeService;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author YeahLiang
 * @Create 2022/03/18
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/employee")
public class EmployeeController {
    private final HsEmployeeService employeeService;

    @RequestMapping("/easyCreateEmployee")
    public ResultDTO<Boolean> easyCreateEmployee(@RequestBody HsEmployee hsEmployee) {
        return ResultDTO.success(employeeService.save(hsEmployee));
    }

    @RequestMapping("/easyDeleteEmployee/{id}")
    public ResultDTO<Boolean> easyDeleteEmployee(@PathVariable Long id) {
        return ResultDTO.success(employeeService.removeById(id));
    }

    @RequestMapping("/easyUpdateEmployee")
    public ResultDTO<Boolean> easyUpdateEmployee(@RequestBody HsEmployee hsEmployee) {
        return ResultDTO.success(employeeService.updateById(hsEmployee));
    }

    @RequestMapping("/easyGetOneEmployee/{id}")
    public ResultDTO<HsEmployee> easyGetOneEmployee(@PathVariable Long id) {
        return ResultDTO.success(employeeService.getById(id));
    }

    @GetMapping("/getEmpByDeptId/{id}")
    public ResultDTO<List<HsEmployee>> getEmpByDeptId(@PathVariable Long id){
        return ResultDTO.success(employeeService.getEmpByDeptId(id));
    }

    @PostMapping("/updateDeptOfEmployee")
    public ResultDTO<Boolean> updateDeptOfEmployee(@RequestBody DeptDTO dto){
        return ResultDTO.success(employeeService.updateDeptOfEmployee(dto));
    }

    @PostMapping("/examineIdCard")
    public ResultDTO examineIdCard(@RequestBody ExamineDTO examineDTO){
        return ResultDTO.success(employeeService.examineIdCard(examineDTO));
    }

    @PostMapping("listEmployee")
    public ResultDTO<PageInfo<EmployeeVo>> listEmployee(@RequestBody HsEmployeeDTO hsEmployeeDTO){
        return ResultDTO.success(employeeService.listEmployee(hsEmployeeDTO));
    }

    @PostMapping("/updateStatus/{id}")
    public ResultDTO<Boolean> lockOrUnlockEmployee(@PathVariable("id") Long id, Integer status){
        return ResultDTO.success(employeeService.lockOrUnlockEmployee(id,status));
    }
}
